package com.ruoyi.web.controller.personnel;

import java.util.List;

import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.personnel.domain.FwVisitorUser;
import com.ruoyi.personnel.service.IFwVisitorUserService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 访客信息Controller
 *
 * @author ruoyi
 * @date 2020-02-21
 */
@Controller
@RequestMapping("/personnel/userInfo")
public class FwVisitorUserController extends BaseController {
    private String prefix = "personnel/userInfo";

    @Autowired
    private IFwVisitorUserService fwVisitorUserService;

    @RequiresPermissions("personnel:userInfo:view")
    @GetMapping()
    public String userInfo() {
        return prefix + "/userInfo";
    }

    /**
     * 查询访客信息列表
     */
    @RequiresPermissions("personnel:userInfo:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(FwVisitorUser fwVisitorUser) {
        startPage();
        List<FwVisitorUser> list = fwVisitorUserService.selectFwVisitorUserList(fwVisitorUser);
        return getDataTable(list);
    }

    /**
     * 导出访客信息列表
     */
    @RequiresPermissions("personnel:userInfo:export")
    @Log(title = "访客信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(FwVisitorUser fwVisitorUser) {
        List<FwVisitorUser> list = fwVisitorUserService.selectFwVisitorUserList(fwVisitorUser);
        ExcelUtil<FwVisitorUser> util = new ExcelUtil<FwVisitorUser>(FwVisitorUser.class);
        return util.exportExcel(list, "userInfo");
    }

    /**
     * 新增访客信息
     */
    @GetMapping("/add")
    public String add() {
        return prefix + "/add";
    }

    /**
     * 新增保存访客信息
     */
    @RequiresPermissions("personnel:userInfo:add")
    @Log(title = "访客信息", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(FwVisitorUser fwVisitorUser) {
        return toAjax(fwVisitorUserService.insertFwVisitorUser(fwVisitorUser));
    }

    /**
     * 修改访客信息
     */
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap) {
        FwVisitorUser fwVisitorUser = fwVisitorUserService.selectFwVisitorUserById(id);
        mmap.put("fwVisitorUser", fwVisitorUser);
        return prefix + "/edit";

    }

    /**
     * 修改保存访客信息
     */
    @RequiresPermissions("personnel:userInfo:edit")
    @Log(title = "访客信息", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(FwVisitorUser fwVisitorUser) {
        return toAjax(fwVisitorUserService.updateFwVisitorUser(fwVisitorUser));
    }

    /**
     * 删除访客信息
     */
    @RequiresPermissions("personnel:userInfo:remove")
    @Log(title = "访客信息", businessType = BusinessType.DELETE)
    @PostMapping("/remove")
    @ResponseBody
    public AjaxResult remove(String ids) {
        return toAjax(fwVisitorUserService.deleteFwVisitorUserByIds(ids));
    }
}
